home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Now 11 / CD-ROM Now MegaDisc 11 (1995-02).iso / _bbs / fileid / find_diz.c < prev    next >
C/C++ Source or Header  |  1994-11-25  |  2KB  |  83 lines

  1. /*
  2.  * find_diz.c
  3.  * this finds the file description in the index file.
  4.  * 
  5.  */
  6.  
  7. #include <ctype.h>
  8. #include <stdarg.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. FILE *logfile;
  14.  
  15. static void _Cdecl    print_err(const char *fmt, ...);
  16.  
  17. static char copyright[] = "make_diz, Copyright (C) 1994 Walnut Creek CDROM\n";
  18.  
  19. void _Cdecl
  20. main(int argc, char *argv[]) {
  21.     FILE *fd;
  22.     FILE *out;
  23.     char buf1[100];
  24.     char buf[2000];
  25.     char *p;
  26.  
  27.     sprintf(buf1, "%s\\wildcat.txt", argv[2]);
  28.  
  29.     if (NULL == (fd = fopen(buf1, "r"))) {
  30.         fprintf(stderr, "Unable to open `%s' on CDROM.\n", buf1);
  31.         exit(1);
  32.     }
  33.  
  34.     p = strrchr(argv[1], '\\') + 1;
  35.  
  36.     while (NULL != fgets(buf, 1998, fd)) {
  37.         if (0 == strncmpi(buf, p, strlen(p))) {
  38.             p = &buf[14];
  39.             while (*p && isspace(*p))
  40.                 ++p;
  41.             if (!*p) {
  42.                 /* no description in index file */
  43.                 fprintf(stderr, "no description in index file |%s|\n",
  44.                         &buf[14]);
  45.                 exit(1);
  46.             }
  47.  
  48.             if (NULL == (out = fopen("file_id.diz", "wt"))) {
  49.                 print_err("erroring opening file_id.diz\n");
  50.                 exit(1);
  51.             }
  52.  
  53.             fprintf(out, "%s", &buf[14]);
  54.             fclose(out);
  55.             
  56.             exit(0);
  57.         }
  58.     }
  59.  
  60.     print_err("unable to find `%s' in `%s'\n", p, buf1);
  61.     exit(1);
  62. }
  63.  
  64. void _Cdecl
  65. print_err(const char *fmt, ...) {
  66.     va_list args;
  67.     char str[500];
  68.  
  69.     va_start(args, fmt);
  70.     vsprintf(str, fmt, args);
  71.     va_end(args);
  72.  
  73.     if (NULL == (logfile = fopen("logfile", "at"))) {
  74.         fprintf(stderr, "erroring opening logfile\n");
  75.         exit(1);
  76.     }
  77.  
  78.     fprintf(logfile, "%s", str);
  79.     fclose(logfile);
  80.     
  81.     fprintf(stderr, "%s", str);
  82. }
  83.